home *** CD-ROM | disk | FTP | other *** search
/ MacFormat 1995 January / macformat-020.iso / Shareware City / Developers / apps.to.go / DTS.Lib / DTS.Lib.headers / File2.h < prev    next >
Encoding:
C/C++ Source or Header  |  1994-06-10  |  13.1 KB  |  363 lines  |  [TEXT/KAHL]

  1. #ifndef __FILE2__
  2. #define __FILE2__
  3.  
  4. #ifndef __TYPES__
  5. #include <Types.h>
  6. #endif
  7.  
  8.  
  9.  
  10. OSErr            DefaultInitDocument(FileRecHndl frHndl, short version,
  11.                                     short numUndos, short numSaveUndos);
  12.     /*
  13.     **    ¶ Do standard AppsToGo document initialization.
  14.     **
  15.     **    INPUT:    frHndl            Recently created (most likely by the framework) file
  16.     **                            reference handle.
  17.     **            version            Version number to store into the document.
  18.     **            numUndos        The number of undos to be managed by the hierarchical
  19.     **                            document architecture.
  20.     **            numSaveUndos    The number of undos to be saved with the document
  21.     **                            (commonly none, so 0).
  22.     **    RESULT:    OSErr
  23.     **
  24.     **    This function does the standard document initialization.  The standard document
  25.     **    uses the hierarchical document package TreeObj.  Read the TreeObj documentation for
  26.     **    more information. */
  27.  
  28.  
  29.  
  30. OSErr            DisposeDocument(FileRecHndl frHndl);
  31.     /*
  32.     **    ¶ Dispose of an AppsToGo document.
  33.     **
  34.     **    INPUT:    frHndl        The file reference being disposed of.
  35.     **    RESULT:    OSErr
  36.     **
  37.     **    This function is automatically called by such functions as DisposeOneWindow.  It
  38.     **    calls the designated free document procedure, which by default is FreeDocument.
  39.     **    The free document procedure is responsible for disposing of any and all handles
  40.     **    that were created by the init document procedure. */
  41.  
  42.  
  43.  
  44. OSErr            NewDocument(FileRecHndl *returnHndl, OSType sftype, Boolean incTitleNum);
  45.     /*
  46.     **    ¶ Create new AppsToGo document.
  47.     **
  48.     **    INPUT:    sftype            The OSType of the desired document.
  49.     **            incTitleNum        Pass in true if you want the document number which is
  50.     **                            (optionally) appended to the title incremented.
  51.     **    OUTPUT:    returnHndl        The frHndl created is returned here.
  52.     **                            Note that there are two special cases that you can call
  53.     **                            this function.  The purpose for both is to change
  54.     **                            the untitledCount value.  If you pass in an sftype of 0,
  55.     **                            then the frHndl value is used as an indicator as to what
  56.     **                            to do with the untitledCount value.  If you pass in 0
  57.     **                            for the frHndl value, untitledCount is reset to 0.
  58.     **                            If you pass in a -1, untitledCount is decremented.
  59.     **    RESULT:    OSErr            If an error is returned, then there is no returnHndl.
  60.     **
  61.     **    This function is called by the application, directly or indirectly.  Even if you
  62.     **    have used the application editor to set up AppWannabe to automatically open
  63.     **    document windows (file-based or not), this gets called.
  64.     **
  65.     **    NewDocument first calls the AppWannabe function InitDocumentSize to allow the
  66.     **    application to declare how large the file reference handle should be.  It then
  67.     **    creates the frHndl based on the return value of InitDocumentSize
  68.     **    (via NewHandleClear), and then initializes the fields to their default values.
  69.     **
  70.     **    NewDocument then calls another AppWannabe function called InitDocument.  The
  71.     **    purpose of this AppWannabe function is to change any of the defaults that aren’t
  72.     **    appropriate for the document.
  73.     **
  74.     **    Note that the typical way to create document with AppsToGo (because it is the
  75.     **    easiest) is to create them with the application editor.  NewDocument, for backwards
  76.     **    compatibility notes if there is an AppsToGo application editor entry for this
  77.     **    OSType.  If so, then there is a lot more information directly available for this
  78.     **    document.  If the document being created was described with the editor, then read
  79.     **    part 1 below.  If you are calling NewDocument directly without having described
  80.     **    this OSType with the AppsToGo application editor, then read part 2 below.
  81.     **    (The part 2 technique is really only for backwards compatibility.)
  82.     **
  83.     **    PART 1:    The document title is entered in the AppsToGo editor.  If there is no
  84.     **            title entered there, or if the title starts with a space, then no default
  85.     **            title is placed in the document reference.  (When a window is created, if
  86.     **            there is no document name, then the 'WIND' resource title is used as-is
  87.     **            instead.)
  88.     **
  89.     **            If true is passed in for incTitleNum, then if a valid title was entered in
  90.     **            the AppsToGo editor, then untitledCount is incremented, and then appended
  91.     **            to the title.
  92.     **
  93.     **    PART 2:    New documents will be created with a default title.  This title is created
  94.     **            by appending a number to the corresponding STR# individual string.  The
  95.     **            STR# resource ID #259 holds the default text for the window titles.  Which
  96.     **            string number is determined by the OSType array gTypeList.  gTypeList
  97.     **            contains all of the file types that can be opened by the application.  The
  98.     **            list is walked, and the location in the gTypeList array that holds the
  99.     **            correct file type is used as an index into the STR# resource.  If the file
  100.     **            type isn’t found in the list, then the first string in the STR# resource
  101.     **            is used.
  102.     **
  103.     **            The next greatest integer is appended to the end of the individual string
  104.     **            selected for the document.  If incTitleNum is true, then the global
  105.     **            integer is first incremented prior to appending the number.
  106.     **
  107.     **            If you want to create a document with the title found in the 'WIND'
  108.     **            resource, first call NewDocument.  After you have the frHndl for the
  109.     **            document, set the file name in the (*frHndl)->fileState.fss.name field to
  110.     **            an empty string.  When the window is opened for this document, if this
  111.     **            name is an empty string, it titles the window according to what is found
  112.     **            in the 'WIND' resource for that window.  If this field is not an empty
  113.     **            string, then the 'WIND' title is overridden, and the file name is used. */
  114.  
  115.  
  116.  
  117. OSErr            OpenDocument(FileRecHndl *result, FSSpecPtr fileToOpen, char permission);
  118.     /*
  119.     **    ¶ Open an AppsToGo document.
  120.     **
  121.     **    INPUT:    fileToOpen        A pointer to the FSSpec for the file to open, or nil if
  122.     **                            the user should determine via StandardFile.
  123.     **                            Also, if you want to open a movie, pass in kOpenMovie for
  124.     **                            the FSSpec pointer.
  125.     **            permission        As you would expect -- fsRdPerm or fsRdWrPerm.
  126.     **    RESULT:    OSErr
  127.     **
  128.     **    This function does the human-interface thing for opening a document.  It
  129.     **    also calls NewDocument to initialize a document.  To actually read in
  130.     **    the data, OpenDocument calls the designated read document procedure, which by
  131.     **    default is ReadDocument.  The read document procedure is responsible for reading
  132.     **    the document data into ram in association with the FileRecHndl created by
  133.     **    NewDocument. */
  134.  
  135.  
  136.  
  137. OSErr            SaveDocument(FileRecHndl frHndl, WindowPtr window, short saveMode);
  138.     /*
  139.     **    ¶ Save an AppsToGo document.
  140.     **
  141.     **    INPUT:    frHndl
  142.     **            window
  143.     **            saveMode    The mode for saving -- kSave, kSaveAs, kClose, kQuit
  144.     **    RESULT:    OSErr
  145.     **
  146.     **    This function does the human-interface thing for saving a document.  The
  147.     **    human-interface presented to the user is determined by the saveMode.
  148.     **
  149.     **    To actually write out the data, SaveDocument calls the designated write document
  150.     **    procedure, which by default is WriteDocument.  The write document procedure is
  151.     **    responsible for writing the document data to the designated file. */
  152.  
  153.  
  154.  
  155. void            ConvertOldToNewSFReply(SFReply *oldReply, StandardFileReply *newReply);
  156.     /*
  157.     **    ¶ Convert pre-system-7 standard file record to a system-7 record.
  158.     **
  159.     **    INPUT:    oldReply
  160.     **    OUTPUT:    newReply
  161.     **
  162.     **    When running on a pre-7.0 system, SFGetFile or SFPutFile is called.  Then
  163.     **    ConvertOldToNewSFReply is called to convert the reply record to the new
  164.     **    format.  This allows the rest of the application to use only a single
  165.     **    record format. */
  166.  
  167.  
  168.  
  169. Boolean            DisplayGetFile(StandardFileReply *reply, short typeListLen,
  170.                                SFTypeList typeList);
  171.     /*
  172.     **    ¶ Do a system-independent (system 6 or 7+) Standard Get File.
  173.     **
  174.     **    INPUT:    typeListLen        Length of typeList.
  175.     **            typeList        List of acceptable OSTypes to be displayed by
  176.     **                            StandardFile.
  177.     **    OUTPUT:    reply            Reply record -- result of StandardFile.
  178.     **    RESULT:    Boolean            Returns true if reply is good.
  179.     **
  180.     **    Simple routine to display a list of files with our file type, independent of
  181.     **    system (6 or 7). */
  182.  
  183.  
  184.  
  185. Boolean            DisplayPutFile(StandardFileReply *reply);
  186.     /*
  187.     **    ¶ Do a system-independent (system 6 or 7+) Standard Put File.
  188.     **
  189.     **    IN/OUT:    reply            Reply record for standard file.
  190.     **    RESULT:    Boolean            Returns true if reply is good.
  191.     **
  192.     **    Displays the StandardFile PutFile dialog box. Fills out the passed reply
  193.     **    record, and returns the sfGood field as a result. */
  194.  
  195.  
  196.  
  197. OSErr            UseDocResFile(FileRecHndl frHndl, short *oldRes, char perm);
  198.     /*
  199.     **    ¶ Use (and possibly create) resource fork of designated file.
  200.     **
  201.     **    INPUT:    frHndl
  202.     **            perm
  203.     **    OUTPUT:    oldRes
  204.     **    RESULT:    OSErr
  205.     **
  206.     **    Use the resource fork for the designated document file.  This function
  207.     **    also returns the old CurResFile, so you can set it back when you are done.
  208.     **    Simply call this function, whether or not you have a resource fork.  If
  209.     **    there isn’t a resource fork, then one will be created.  If there is one,
  210.     **    but it isn’t open yet, it will be opened.  If it is already opened, it
  211.     **    sets it as the current resource fork.  What more do you want? */
  212.  
  213.  
  214.  
  215. OSErr            CloseDocResFile(FileRecHndl frHndl);
  216.     /*
  217.     **    ¶ Close document res file.
  218.     **
  219.     **    INPUT:    frHndl
  220.     **    RESULT:    OSErr
  221.     **
  222.     **    If there is a resource fork opened for this document (via UseDocResFile),
  223.     **    this closes it. */
  224.  
  225.  
  226.  
  227. long            GetModNum(void);
  228.     /*
  229.     **    ¶ Get modification number of document.
  230.     **
  231.     **    Get the modification number for the document.  TreeObj automatically
  232.     **    increments this. */
  233.  
  234.  
  235.  
  236. Boolean            GetDocDirty(FileRecHndl frHndl);
  237.     /*
  238.     **    ¶ Find out if the document is dirty.
  239.     **
  240.     **    INPUT:    frHndl
  241.     **
  242.     **    Get the dirty state of the document. */
  243.  
  244.  
  245.  
  246. Boolean            GetWindowDirty(WindowPtr window);
  247.     /*
  248.     **    ¶ Find out if a window’s document is dirty.
  249.     **
  250.     **    INPUT:    window
  251.     **
  252.     **    Given a window, return the dirty state of the associated document. */
  253.  
  254.  
  255.  
  256. void            SetDocDirty(FileRecHndl frHndl);
  257.     /*
  258.     **    ¶ Set the document dirty.
  259.     **
  260.     **    INPUT:    frHndl
  261.     **
  262.     **    Set the document dirty. */
  263.  
  264.  
  265.  
  266. void            SetWindowDirty(WindowPtr window);
  267.     /*
  268.     **    ¶ Set the window’s document dirty.
  269.     **
  270.     **    INPUT:    window
  271.     **
  272.     **    Given a window, set the associated document as dirty. */
  273.  
  274.  
  275.  
  276. OSErr            SetDefault(short newVRefNum,  long newDirID,
  277.                            short *oldVRefNum, long *oldDirID);
  278.     /*
  279.     **    ¶ Set default volume and directory.
  280.     **
  281.     **    INPUT:    newVRefNum
  282.     **            newDirID
  283.     **    OUTPUT:    oldVRefNum
  284.     **            oldDirID
  285.     **    RESULT:    OSErr
  286.     **
  287.     **    The SetDefault function sets the default volume and directory to the volume
  288.     **    specified by newVRefNum and the directory specified by newDirID. The current
  289.     **    default volume and directory are returned in oldVRefNum and oldDir and should be
  290.     **    used to restore things to their previous condition *as soon as possible* with the
  291.     **    RestoreDefault function. These two functions are designed to be used as a wrapper
  292.     **    around Standard C I/O routines where the location of the file is implied to be the
  293.     **    default volume and directory. In other words, this is how you should use these
  294.     **    functions:
  295.     **
  296.     **        err = SetDefault(newVRefNum, newDirID, &oldVRefNum, &oldDirID);
  297.     **        if (!err)
  298.     **            {
  299.     **                -- call the Stdio functions like remove, rename, tmpfile, fopen,   --
  300.     **                -- freopen, etc. or non-ANSI extentions like fdopen, fsetfileinfo, --
  301.     **                -- create, open, unlink, etc. here!                                   --
  302.     **
  303.     **                err = RestoreDefault(oldVRefNum, oldDirID);
  304.     **            }
  305.     **
  306.     **    By using these functions as a wrapper, you won’t need to open a working directory
  307.     **    (because they use HSetVol) and you won’t have to worry about the effects of using
  308.     **    HSetVol (documented in Technical Note #140: Why PBHSetVol is Dangerous 
  309.     **    and in the Inside Macintosh: Files book in the description of the HSetVol and 
  310.     **    PBHSetVol functions) because the default volume/directory is restored before 
  311.     **    giving up control to code that might be affected by HSetVol.
  312.     **    Use this and the below call instead of the old-style FSpSetWD and FSpResetWD. */
  313.  
  314.  
  315.  
  316. OSErr            RestoreDefault(short oldVRefNum, long oldDirID);
  317.     /*
  318.     **    ¶ Restore default volume and directory.
  319.     **
  320.     **    INPUT:    oldVRefNum
  321.     **            oldDirID
  322.     **    RESULT:    OSErr
  323.     **
  324.     **    Resets the default directory to what it was prior to calling SetDefault. */
  325.  
  326.  
  327.  
  328. OSErr            GetFileLocation(short refNum, short *vRefNum, long *dirID,
  329.                                 StringPtr fileName);
  330.     /*
  331.     **    ¶ Get vRefNum, dirID, and fileName of a file.
  332.     **
  333.     **    INPUT:    refNum
  334.     **    OUTPUT:    vRefNum
  335.     **            dirID
  336.     **            fileName
  337.     **    RESULT:    OSErr
  338.     **
  339.     **    Get the vRefNum, dirID, and fileName of a file.
  340.     **    (vRefNum and dirID are its location). */
  341.  
  342.  
  343.  
  344. OSErr            CurResOnly(Handle *hndl);
  345.     /*
  346.     **    ¶ Find out if resource belongs to current res file.
  347.     **
  348.     **    IN/OUT:    hndl
  349.     **    RESULT:    OSErr
  350.     **
  351.     **    After getting a resource, you can’t actually be sure that it came from the current
  352.     **    resource file.  Even if you make a call such as Get1Resource, starting with
  353.     **    system 7.1, you can’t really be sure that it came from the current resource file.
  354.     **    (The resource files may be overridden, or they may be flagged to be extended, as is
  355.     **    the case with font files.)  This checks to see that the resource actually came from
  356.     **    the current resource file.  If it didn’t, then the handle returned is nil, and the
  357.     **    error returned is resNotFound.  (You probably don’t need this function unless you
  358.     **    are doing some kind of resource-editing function.) */
  359.  
  360.  
  361.  
  362. #endif
  363.